﻿using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class AssetDataManager
{
    public static Dictionary<System.Type, ScriptableObject> _datas = new Dictionary<System.Type,ScriptableObject>();

    public static T Get<T>() where T : ScriptableObject
    {
        return Get<T>("AssetData", typeof(T).Name);
    }

    /// <summary>
    /// 获取指定数据信息
    /// </summary>
    public static T Get<T>(string path, string resName) where T : ScriptableObject
    {
        ScriptableObject scriptableObject = null;
        System.Type type = typeof(T);

        if (!_datas.TryGetValue(type, out scriptableObject))
        {
            string pathAndName = string.Format("{0}/{1}", path, resName);
            T t = Resources.Load(pathAndName, type) as T;
            Debug.Log(path + "/" + resName);
            _datas[type] = t;

            if (null == t)
            {
                Debug.LogError("[Error]DataManager::Get. Resources/Data Folder not exist file " + type.Name);
            }
        }

        return _datas[type] as T;
    }
}

